@echo off
cls
echo ========== Learning Platform - Restart All Services ==========
echo.
echo Stopping all running services...

echo Killing Java process (backend)...
taskkill /F /IM java.exe >nul 2>&1
echo Killing Python process (AI service)...
taskkill /F /IM python.exe >nul 2>&1
echo Killing Node process (frontend)...
taskkill /F /IM node.exe >nul 2>&1

echo.
echo Waiting for 5 seconds to ensure all services are stopped...
ping 127.0.0.1 -n 6 >nul
echo.
echo Restarting all services...
start "Backend Service" /D "d:/code/learning-platform/backend" cmd /c mvnw.cmd spring-boot:run
echo Backend service started (port 8080)
ping 127.0.0.1 -n 10 >nul
echo.
start "AI Service" /D "d:/code/learning-platform/ai" cmd /c python main.py
echo AI service started (port 8000)
ping 127.0.0.1 -n 5 >nul
echo.
start "Frontend Service" /D "d:/code/learning-platform/frontend" cmd /c npm run dev
echo Frontend service started (port 5173)
echo.
echo ========== Services Restarted ==========
echo.
echo All services have been restarted. Please wait 1-2 minutes for complete initialization.
echo You can check the status of services at these URLs:
echo - Backend: http://localhost:8080/actuator/health
echo - Frontend: http://localhost:5173
echo - AI Service: http://localhost:8000/docs
echo.
echo Press any key to close this window...
pause >nul